import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class LoginToDashboard {

	public static void main(String[] args) {

		

		final JFrame frame = new JFrame("Login page");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(450, 250);

		JPanel login = new JPanel();
		frame.add(login);

		final JLabel un = new JLabel();
		un.setText("user :");
		login.add(un);

		final JTextField utf = new JTextField();
		utf.setPreferredSize(new Dimension(100, 20));
		login.add(utf);

		final JLabel pass = new JLabel();
		pass.setText("password :");
		login.add(pass);

		final JTextField ptf = new JTextField();
		ptf.setPreferredSize(new Dimension(100, 20));
		login.add(ptf);

		JButton lbutton = new JButton("login");
		lbutton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub

				String username = new String(utf.getText());
				String password = new String(ptf.getText());

				if (username.equals("karol") || password.equals("1234")) {
					JLabel loginPerformDialog = new JLabel("loading ...");
					JOptionPane.showMessageDialog(null, loginPerformDialog);

				}

				else {
					JLabel errorDialog = new JLabel(
							"You must enter valid a username and password to login ");
					JOptionPane.showMessageDialog(null, errorDialog);
				}

			}
		});

		login.add(lbutton);

		frame.show();

	}

}
